﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling.Diagrams;
using System.Drawing;
using Microsoft.VisualStudio.Modeling;

namespace UofCASE.AgileProductLinerDSL {

    public partial class TestShape {

        private void OnCollapsedChangedTestShape(object sender, EventArgs e) {
            this.UpdateVisibility();
        }

        private void UpdateVisibility() {
            if (this.IsVisibleDP) this.SetShowHideState(true);
            else this.SetShowHideState(false);
        }

        public void RegisterForCollapsingChangedEvent(TestPortShape tPortShape) {
            tPortShape.CollapsingChanged += OnCollapsedChangedTestShape;
        }

        public void UnregisterForCollapsingChangedEvent(TestPortShape tPortShape) {
            tPortShape.CollapsingChanged -= OnCollapsedChangedTestShape;
        }

        public override void OnMouseEnter(DiagramPointEventArgs e) {
            base.OnMouseEnter(e);
            ShowPreview();
        }

        public override void OnMouseLeave(DiagramPointEventArgs e) {
            base.OnMouseLeave(e);
            HidePreview();
        }

        public void ShowPreview() {
            foreach (FeaturePortShape fPortShape in this.RelativeChildShapes) {
                foreach (LinkShape link in fPortShape.Link) {
                    link.SetShowHideState(true);
                }
            }
        }

        public void HidePreview() {
            foreach (FeaturePortShape fPortShape in this.RelativeChildShapes) {
                foreach (TestConnector testCon in fPortShape.Link) {
                    testCon.UpdateVisibility();
                }
            }
        }
  
    }
}
